<?php

namespace app\model;

use think\Model;

class RechargeLimitTemplateCompany extends Model
{
	// 设置当前模型对应的数据表
	protected $name = 'recharge_limit_template_company';

	public function company()
	{
		return $this->hasOne(Company::class, 'id', 'company_id');
	}

	public function deleteByRechargeLimitTemplateId(int $rechargeLimitTemplateId)
	{
		return $this->where(['recharge_limit_template_id' => $rechargeLimitTemplateId])->delete();
	}

	public function selectFirstByRechargeLimitTemplateIdAndCompanyId(array $fields, int $rechargeLimitTemplateId, $companyId)
	{
		$data = $this->field($fields)->where(['recharge_limit_template_id' => $rechargeLimitTemplateId, 'company_id' => $companyId])->find();

		return empty($data) ? [] : $data->toArray();
	}

	// 根据条件获取数据
    public function getDataByWhere($where = [], $fields = 'company_id')
    {
        $data = $this::where($where)->field($fields)->select();
        return $data ? $data->toArray() : [];
    }
}
